﻿Imports System
Imports System.Windows
Imports System.Windows.Forms
Imports System.Windows.Forms.Control

Namespace XPControl
    Public NotInheritable Class TextBox

        Private Shared Ctrl As System.Windows.Forms.Control

        Public Shared GotForeColor As System.Drawing.Color = System.Drawing.Color.Black
        Public Shared GotBackColor As System.Drawing.Color = System.Drawing.Color.GreenYellow

        Public Shared LostForeColor As System.Drawing.Color = System.Drawing.SystemColors.ControlText
        Public Shared LostBackColor As System.Drawing.Color = System.Drawing.Color.LightCyan

        Public Shared Sub TextBox_GotFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim TextBox As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            TextBox.ForeColor = GotForeColor
            TextBox.BackColor = GotBackColor
            If TextBox.Text = "0.00" Then
                TextBox.Text = ""
            End If
            TextBox.SelectAll()
        End Sub

        Public Shared Sub TextBox_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim TextBox As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            TextBox.ForeColor = LostForeColor
            TextBox.BackColor = LostBackColor
        End Sub

        Public Shared Sub TextBoxNum_LostFocus(ByVal sender As System.Object, ByVal e As System.EventArgs)
            Dim TextBox As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            TextBox.ForeColor = LostForeColor
            TextBox.BackColor = LostBackColor
            If TextBox.Text = "" Then
                TextBox.Text = "0.00"
            ElseIf TextBox.Text <> "" Then
                Dim TMP As Double = CDbl(TextBox.Text)
                TextBox.Text = Format(TMP, "#,##0.00")
            End If
        End Sub

        Public Shared Sub NumOnly_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
            Dim TextBoxs As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            If TextBoxs.Text.Length < 255 Then
                If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "." Then
                    e.Handled = True
                Else
                    If e.KeyChar = "." Then
                        e.Handled = True
                    End If
                End If
            Else
                e.Handled = True
            End If
        End Sub

        Public Shared Sub Phone_Keypress(ByVal Sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
            Dim TextBoxs As System.Windows.Forms.TextBox = CType(Sender, System.Windows.Forms.TextBox)
            If TextBoxs.Text.Length < 255 Then
                If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "-" And Not e.KeyChar = "#" And Not e.KeyChar = "," Then
                    e.Handled = True
                    'Else
                    ' If e.KeyChar = "-" And TextBoxs.Text.IndexOf("-") <> -1 Then
                    'e.Handled = True
                    'End If

                    'If e.KeyChar = "#" And TextBoxs.Text.IndexOf("#") <> -1 Then
                    'e.Handled = True
                    'End If
                End If
            Else
                e.Handled = True
            End If
        End Sub

        Public Shared Sub NumReal_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs)
            Dim TextBoxs As System.Windows.Forms.TextBox = CType(sender, System.Windows.Forms.TextBox)
            If TextBoxs.Text.Length < 255 Then
                If Not Char.IsDigit(e.KeyChar) And Not Char.IsControl(e.KeyChar) And Not e.KeyChar = "." Then
                    e.Handled = True
                Else
                    If e.KeyChar = "." And TextBoxs.Text.IndexOf(".") <> -1 Then
                        e.Handled = True
                    End If
                End If
            Else
                e.Handled = True
            End If
        End Sub

        Public Shared Sub ClearTextBoxInGB(ByVal GB As System.Windows.Forms.GroupBox)
            For Each Ctrl As System.Windows.Forms.Control In GB.Controls
                If TypeOf Ctrl Is System.Windows.Forms.TextBox Then Ctrl.Text = ""
            Next
        End Sub

        Public Shared Sub ClearTextBoxInPNL(ByVal PNL As System.Windows.Forms.Panel)
            For Each Ctrl As System.Windows.Forms.Control In PNL.Controls
                If TypeOf Ctrl Is System.Windows.Forms.TextBox Then Ctrl.Text = ""
            Next
        End Sub

        Public Shared Sub ClearTextBoxInTabPage(ByVal Tab As System.Windows.Forms.TabPage)
            For Each Ctrl As System.Windows.Forms.Control In Tab.Controls
                If TypeOf Ctrl Is System.Windows.Forms.TextBox Then Ctrl.Text = ""
            Next
        End Sub

        Public Shared Sub ClearTextBoxInTab(ByVal Tab As System.Windows.Forms.TabControl)
            For Each Ctrl As System.Windows.Forms.Control In Tab.Controls
                If TypeOf Ctrl Is System.Windows.Forms.TabPage Then
                    For Each Ctrl2 As System.Windows.Forms.Control In Ctrl.Controls
                        If TypeOf Ctrl2 Is System.Windows.Forms.Panel Then
                            For Each Ctrl3 As System.Windows.Forms.Control In Ctrl2.Controls
                                If TypeOf Ctrl3 Is System.Windows.Forms.TextBox Then
                                    Ctrl3.Text = ""
                                End If
                            Next
                        End If
                        If TypeOf Ctrl2 Is System.Windows.Forms.TextBox Then
                            Ctrl2.Text = ""
                        End If
                    Next
                End If
                If TypeOf Ctrl Is System.Windows.Forms.TextBox Then
                    Ctrl.Text = ""
                End If
            Next
        End Sub

        Public Shared Sub EnableTextBoxInGB(ByVal GB As System.Windows.Forms.GroupBox)
            For Each Ctrl As System.Windows.Forms.Control In GB.Controls
                If TypeOf Ctrl Is System.Windows.Forms.TextBox Then Ctrl.Enabled = True
            Next
        End Sub

        Public Shared Sub DisableTextBoxInGB(ByVal GB As System.Windows.Forms.GroupBox)
            For Each Ctrl As System.Windows.Forms.Control In GB.Controls
                If TypeOf Ctrl Is System.Windows.Forms.TextBox Then Ctrl.Enabled = False
            Next
        End Sub

        Public Shared Sub EnableTextBoxInTab(ByVal Tab As System.Windows.Forms.TabPage)
            For Each Ctrl As System.Windows.Forms.Control In Tab.Controls
                If TypeOf Ctrl Is System.Windows.Forms.TextBox Then Ctrl.Enabled = True
            Next
        End Sub

        Public Shared Sub DisableTextBoxInTab(ByVal Tab As System.Windows.Forms.TabPage)
            For Each Ctrl As System.Windows.Forms.Control In Tab.Controls
                If TypeOf Ctrl Is System.Windows.Forms.TextBox Then Ctrl.Enabled = False
            Next
        End Sub

    End Class
End Namespace
